#include"header/token.h"
#include<stdlib.h>
#include<stdio.h>

token init_token(int type,char * letter,int digit){
    token t = (token)calloc(1,sizeof(token_));
    t->type = type;
    switch(type){
        case TOKEN_ID:
            t->lexeme.letter = letter;
            break;
        case TOKEN_NUM:
            t->lexeme.digit = digit;
            break;
        default:
            break;
    }
    return t;
}

char * token_letter(token t){
    return t->lexeme.letter;
}

int token_digit(token t){
    return t->lexeme.digit;
}

void log_token(token t){
    char * c = 0;
    switch (t->type){
        case TOKEN_ID:
            printf("Id: %s",t->lexeme.letter);
            break;
        case TOKEN_NUM:
            printf("Num: %d",t->lexeme.digit);
            break;
        case TOKEN_EOF:
            printf("EOF");
            break;
        case TOKEN_IF:
            printf("If");
            break;
        case TOKEN_ELSE:
            printf("Else");
            break;
        case TOKEN_FOR:
            printf("For");
            break;
        case TOKEN_WHILE:
            printf("While");
            break;
        case TOKEN_SEMICOLON:
            printf("Sym ;");
            break;
        case TOKEN_COMMA:
            printf("Sym ,");
            break;
        case TOKEN_ADD:
            printf("Sym +");
            break;
        case TOKEN_MINUS:
            printf("Sym -");
            break;
        case TOKEN_DIV:
            printf("Sym /");
            break;
        case TOKEN_GREAT:
            printf("Sym >");
            break;
        case TOKEN_GREAT_EQUAL:
            printf("Sym >=");
            break;
        case TOKEN_LESS:
            printf("Sym <");
            break;
        case TOKEN_LESS_EQUAL:
            printf("Sym <=");
            break;
        case TOKEN_ASSIGN:
            printf("Sym =");
            break;
        case TOKEN_EQUAL:
            printf("Sym ==");
            break;
        case TOKEN_NOT:
            printf("Sym !");
            break;
        case TOKEN_NOT_EQUAL:
            printf("Sym !=");
            break;
        case TOKEN_LEFT_BRACE:
            printf("Sym (");
            break;
        case TOKEN_RIGHT_BRACE:
            printf("Sym )");
            break;
        case TOKEN_LEFT_SBRACE:
            printf("Sym [");
            break;
        case TOKEN_RIGHT_SBRACE:
            printf("Sym ]");
            break;
        case TOKEN_RIGHT_CBRACE:
            printf("Sym }");
            break;
        case TOKEN_LEFT_CBRACE:
            printf("Sym {");
            break;
        case TOKEN_INT:
            printf("Int");
            break;
        case TOKEN_VOID:
            printf("Void");
            break;
        case TOKEN_STRUCT:
            printf("Struct");
            break;
        default:
            printf("Token");
            break;
    }
    puts("");
}
